

// source idl: com.erp.gis.idl.GisManageAo.java

#ifndef GISMANAGEAO_STUB_4_WEB_H
#define GISMANAGEAO_STUB_4_WEB_H

#include <string>
#include <sstream>
#include "app_platform/cmd_obj.h"
#include "app_platform/cgi_stub_cntl.h"
#include "c2cent/base/basestub4web.h"
#include "app_platform/cntl_info.h"
#include "app_platform/intf_serializable.h"
#include "app_platform/intf_service_object.h"
#include "erp/gis/po/shiptypearealocuspo_gis.h"	
#include "intf_gismanageao.h"

namespace erp
{
namespace gis
{
namespace ao
{
	#define GISMANAGEAO_STUB4WEB_VERSION "ERP_GIS_AO___GISMANAGEAO__STUB4WEB_VERSION__1.0 "__DATE__" "__TIME__
    const std::string GISMANAGEAO_STUB4WEB_NOUSE = GISMANAGEAO_STUB4WEB_VERSION;

	const uint32_t GISMANAGEAO_SHIPTYPEAREALOCUSROWSYNC_REQ_CMD_ID = 0xc0231001; ///同步配送区域轨迹记录请求类  请求命令号
	const uint32_t GISMANAGEAO_SHIPTYPEAREALOCUSROWSYNC_RESP_CMD_ID = 0xc0238001; ///同步配送区域轨迹记录返回类  回应命令号
	


	const uint16_t GISMANAGEAO_MAX_PROTOCAL_VERSION = 2; //>平台支持的最大协议版本号

///////////////////////////// STRUCTS /////////////////////////////////////////////////
	/**
	 *
 	 * 同步配送区域轨迹记录请求类 
	 *
	 *
 	 * @date 2013-10-12 11:09:38
 	 * @version 0
	 */	
	struct CShipTypeAreaLocusRowSyncReq : public IServiceObject, public ISerializableXML
	{
		std::string machineKey;
		std::string source;
		uint32_t sceneId;
		erp::gis::po::CShipTypeAreaLocusPo shipTypeAreaLocusPo;
		std::string inReserve;
		std::string errMsg;
		std::string outReserve;
		
	    virtual uint32_t getCmdId() const { return GISMANAGEAO_SHIPTYPEAREALOCUSROWSYNC_REQ_CMD_ID; }
		virtual bool Serialize(CByteStreamNetwork& bs)
		{
			//检查协议的版本号
		    //if(bs.getVersion() > GISMANAGEAO_MAX_PROTOCAL_VERSION)
		    //return false;
			bs & machineKey;
			bs & source;
			bs & sceneId;
			shipTypeAreaLocusPo.Serialize(bs);
			bs & inReserve;
		    return bs.isGood();
		}
	    virtual void Dump(std::ostream& os)	{}
	
		virtual bool FromXML(const std::string& sXMLContent) { return true; }
		virtual bool ToXML(std::string& sXMLContent) { return true; }
	};
	
	/**
	 *
 	 * 同步配送区域轨迹记录返回类 
	 *
 	 * @date 2013-10-12 11:09:38
 	 * @version 0
	 */	
	struct CShipTypeAreaLocusRowSyncResp : public IServiceObject, public ISerializableXML
	{
		uint32_t dwResult;
		std::string errMsg;
		std::string outReserve;
	
	    virtual uint32_t getCmdId() const { return GISMANAGEAO_SHIPTYPEAREALOCUSROWSYNC_RESP_CMD_ID; }
		virtual bool Serialize(CByteStreamNetwork& bs)
		{
		    bs & dwResult;
			bs & errMsg;
			bs & outReserve;
		    return bs.isGood();
		}
	    virtual void Dump(std::ostream& os)	{}
	
		virtual bool FromXML(const std::string& sXMLContent) { return true; }
		virtual bool ToXML(std::string& sXMLContent) { return true; }
	};
	class CGisManageAoStub4Web : public c2cent::CBaseStub4Web, public IGisManageAo	{
		public:
			uint32_t ShipTypeAreaLocusRowSync(
				const CCntlInfo& rCntlInfo,

				const std::string& machineKey,
				const std::string& source,
				uint32_t sceneId,
				const erp::gis::po::CShipTypeAreaLocusPo& shipTypeAreaLocusPo,
				const std::string& inReserve,
				std::string& errMsg,
				std::string& outReserve
			);
	};
	
	/**
	 *
 	 * 同步配送区域轨迹记录 
	 *
		 *@param String machineKey: 机器码，必填，对应网站cookie中的visitkey，若无则填随机值 				
		 *@param String source: 调用来源文件名称，必填 				
		 *@param uint32_t sceneId: 场景id，必填（目前填0即可） 				
		 *@param ShipTypeAreaLocusPo shipTypeAreaLocusPo: 配送区域轨迹PO 				
		 *@param String inReserve: 请求保留字段 				
		 *@param String errMsg: 错误信息 		
		 *@param String outReserve: 请求保留字段 		
     *
     *@return uint32_t : 0(成功) 其它失败
	 */	
	inline uint32_t CGisManageAoStub4Web::ShipTypeAreaLocusRowSync(
				const CCntlInfo& rCntlInfo,

				const std::string& machineKey,
				const std::string& source,
				uint32_t sceneId,
				const erp::gis::po::CShipTypeAreaLocusPo& shipTypeAreaLocusPo,
				const std::string& inReserve,
				std::string& errMsg,
				std::string& outReserve
	)
	{
		 CShipTypeAreaLocusRowSyncReq oReq;
			oReq.machineKey = machineKey;
			oReq.source = source;
			oReq.sceneId = sceneId;
			oReq.shipTypeAreaLocusPo = shipTypeAreaLocusPo;
			oReq.inReserve = inReserve;
			oReq.errMsg = errMsg;
			oReq.outReserve = outReserve;
		
	    CCGI_STUB_CNTL->setPassport(
	        rCntlInfo.getOperatorUin(), 
	        rCntlInfo.getOperatorKey().c_str(),
	        rCntlInfo.getOperatorClientIP());
	
		if(const_cast<CCntlInfo&>(rCntlInfo).isRouteKeySet())	
			CCGI_STUB_CNTL->setUin(const_cast<CCntlInfo&>(rCntlInfo).getRouteKey());	
	    
	    int iRetCode = 0;
		m_sErrMsg.clear();
		if((iRetCode = CCGI_STUB_CNTL->putSvcObj(&oReq, 0)) != 0)
	    {
			m_sErrMsg = "DoRequest failed: ";
			m_sErrMsg += CCGI_STUB_CNTL->GetLastErrMsg();
	        return iRetCode;
	    }
	    
	    // Send & Recv
		if((iRetCode = SendRecv()) != 0)
		{
			if(99 == iRetCode) // UDP & Need No Response
				return 0;
	
			std::stringstream oss;
			oss << m_lTimeout;
	        m_sErrMsg = "Send & Recv Timeout(";
			m_sErrMsg += oss.str();
			m_sErrMsg += "s) ";
			m_sErrMsg += CCGI_STUB_CNTL->GetLastErrMsg();
			return iRetCode;
	    }
	    
		if(!m_poCmd->isValid(GISMANAGEAO_SHIPTYPEAREALOCUSROWSYNC_RESP_CMD_ID))
	    {
	        std::stringstream oss;
            oss << "Cmd not match: "
                << "Expected cmd=" << std::hex << GISMANAGEAO_SHIPTYPEAREALOCUSROWSYNC_RESP_CMD_ID << std::dec << " != "
                << "actualed cmd=" << std::hex << m_poCmd->getCmdId() << std::dec;
            m_sErrMsg = oss.str();
        
	        return 0xEE0024;
	    }
	    
	    char* pBuf = NULL; uint32_t nLen = 0;
	    m_poCmd->getBuffer(pBuf, nLen);
	    CByteStreamNetwork bs(pBuf, nLen);
	    bs.isStoring(false);
	    
	    CShipTypeAreaLocusRowSyncResp oResp;
	    if(!oResp.Serialize(bs))
	    {
	        m_sErrMsg = "Resp.Serialize(bs) failed";
	        return 0xEE0028;
	    }
		    
			errMsg  = oResp.errMsg;
			outReserve  = oResp.outReserve;
		    
		return oResp.dwResult;
	}
		
}
}
}

#endif /* GISMANAGEAO_STUB_4_WEB_H */
